using System.Diagnostics;
using InfiniTec.Data;

namespace InfiniTec.Expressions
{
    public abstract class CompareExpressionBase<T> : Expression
    {
        private readonly PropertyDefinition<T> _PropertyDefinition;
        private readonly T _Value;


        public PropertyDefinition<T> PropertyDefinition { get { return _PropertyDefinition; } }

        public CompareExpressionBase(PropertyDefinition<T> property, T value)
        {
            _PropertyDefinition = property;
            _Value = value;
        }


        public override bool Evaluate(PropertyCollection properties)
        {
            T actualValue = properties.GetPropertyValue(_PropertyDefinition);

            return Evaluate(_Value, actualValue);
        }

        protected abstract bool Evaluate(T value, T actualValue);

        public T Value
        {
            [DebuggerStepThrough]
            get { return _Value; }
        }
    }
}